Horror Movies and Simulation

December 9, 2024

Shirley Toribio

Diversity of Horror

Netflix Horror Movies

horror_df
  num         genre
1 125        Horror
2 110     Thrillers
3  38      Comedies
4  19 SciFi&Fantasy
5  12          Cult
6   2 Documentaties
7   2      Romantic

Netflix Horror Movies

Beta vs Normal Distribution

Function 1: PI Interval Calculation

CI <- function(data, coverage_prob){ 
  #Generates a normal prediction interval with an intended coverage probability of coverage_prob based on a vector of numeric data
  lower_zscore <- qnorm((1-coverage_prob)/2)
  upper_zscore <- qnorm(((1-coverage_prob)/2) + coverage_prob)
  avg <- mean(data)
  stan_d <- sd(data)
  lower_bound <- avg + lower_zscore*stan_d
  upper_bound <- avg + upper_zscore*stan_d
  return(data.frame(PI_percentage = coverage_prob, lower = lower_bound, upper = upper_bound))
}

Function 2: One simulation of beta-generated data

one_beta_simulation <- function(n, alpha, beta, ci_prop){
  #Assesses prediction accuracy and actual coverage probability of a normal prediction interval when used on a vector of numeric data of size n. The numeric data is generated from a beta distribution with parameters alpha and beta.
  
  cover_df <- CI(rbeta(n, alpha, beta), ci_prop)
  cover_prop <- pbeta(cover_df[1, "upper"], alpha, beta) - pbeta(cover_df[1, "lower"], alpha, beta)
  mean_in_interval <- .5 >= cover_df[1, "lower"] & .5 <= cover_df[1,"upper"]
  param_df <- data.frame(cover = cover_prop, alpha = rep(alpha, nrow(cover_df)), beta = rep(beta, nrow(cover_df)), mean_in_interval = mean_in_interval)
  df <- cbind(cover_df, param_df)
  return(df)
}

Function 3: Multiple Beta simulations

beta_sims_n <- function(n){
  #Iterates over a vector of possible alpha = beta values and applies one_beta_simulation to each possible value of alpha/beta. All simulations use data of sample size n.
  df1 <- map(parameters,\(param) one_beta_simulation(n, param, param, ci) ) %>%
  list_rbind()
  df2 <- data.frame(n = rep(n, nrow(df1)))
  df <- cbind(df2, df1)
  return(df)
}

Simulations

     n PI_percentage     lower     upper     cover alpha beta mean_in_interval
1  443          0.95 0.4403352 0.5568129 0.9428698   133  133             TRUE
2   26          0.95 0.4448102 0.5605112 0.9254171   119  119             TRUE
3  407          0.95 0.4078696 0.5932908 0.9496711    55   55             TRUE
4   92          0.95 0.4457683 0.5502979 0.9422730   165  165             TRUE
5  146          0.95 0.4427047 0.5557669 0.9510242   151  151             TRUE
6  496          0.95 0.4465372 0.5518538 0.9528252   177  177             TRUE
7   15          0.95 0.4492564 0.5509363 0.9357580   165  165             TRUE
8  222          0.95 0.3627269 0.6238542 0.9549371    29   29             TRUE
9  105          0.95 0.4534146 0.5534927 0.9513511   197  197             TRUE
10  29          0.95 0.4033115 0.6006820 0.9691219    59   59             TRUE

Results

FIN